<%--
  Created by IntelliJ IDEA.
  User: 谢兴鑫
  Date: 2022/5/16
  Time: 下午 02:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/ajaxForm.js"></script>
</head>
<body>
<script>
    layui.use(['layedit', 'form','layer'], function () {
        var form = layui.form,layer = layui.layer, layedit = layui.layedit;
        layedit.build('demo'), {  //设置编辑器高度
            height: 180 //设置编辑器高度
        };

        //监听表单提交
        form.on('submit(formbtn)', function () {
            $("#formsbt").ajaxSubmit({
                type: "post",
                url: '${pageContext.request.contextPath}/notice/addNoticeNews',
                success: function (data) {//添加成功的回调函数
                    layer.msg("添加成功", {icon: 6});
                    var index = parent.layer.getFrameIndex(window.name);//获取Frame索引
                    parent.layer.close(index);//关闭当前frame
                    parent.layui.table.reload("tableData");//可以对父窗口进行刷新
                }
            });
        });
        var index = layedit.build('demo');
        form.verify({
            contents: function(value) {
                return layedit.sync(index);
            }
        });

        form.on('select(noticeType)', function (data) {
            if ($("#noticeType").val()==3){
                $("#clazztr").show();
            }else {
                $("#clazztr").hide();
            }
        });
    });
</script>
<script>
    $(document).ready(function(){
        $("#clazztr").hide();
    });
</script>
<form class="layui-form" id="formsbt">
    <div class="layui-form-item">
        <div class="layui-input-inline">
            <input type="hidden" name="noticeId" id="noticeId" placeholder="编号" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" name="title" id="title" lay-verify="required" placeholder="请输入标题"
                   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">必填项</div>

        <div class="layui-input-inline">
            <input type="hidden" name="empId" id="empId" value="${sessionScope.empID}" placeholder="编号" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label">类别</label>
        <div class="layui-input-inline">
            <select name="noticeType" style="left: 50px" id="noticeType" lay-filter="noticeType">
                <option value="1" id="1">全体员工</option>
                <option value="2" id="2">全体学生</option>
                <option value="3" id="3">班级发送</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item" id="clazztr">
        <label class="layui-form-label">班级</label>
        <div class="layui-input-inline">
            <select name="clazz" id="clazz">
                <option name="depName" value="">----请选择----</option>
                <c:forEach items="${studentclassList}" var="s">
                    <option name="depName" value="${s.classId}">${s.className}</option>
                </c:forEach>
            </select>
        </div>
    </div>


    <textarea id="demo" name="content" lay-verify="contents" style="display: none; width: 300px " placeholder="请输入公告内容" ></textarea>


    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <button id="formbtn" type="button" lay-submit lay-filter="formbtn" class="layui-btn layui-btn-normal">
            保存
        </button>
        <button id="reset" type="reset" class="layui-btn layui-btn-normal">
            重置
        </button>
    </div>
</form>
</body>
</html>
